package org.javaopenaccess.web.ui.modelling;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Row;
import org.zkoss.zul.Rows;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

public class NewClassController extends Window{

	private static final long serialVersionUID = -786072954966631702L;
	//This should be in session, only works now for 1 user... very bad code
	private static int attributeCounter = 0;
	
	private Logger logger = LoggerFactory.getLogger(this.getClass().getName());
	public void addRow(){
		logger.info("addin attribute row to ui");
		Rows rows = (Rows)this.getFellow("attrs");
		Row newRow = new Row();
		
		//new name column
		Textbox nameBox = (Textbox)this.getFellow("attrName");
		Textbox newNameBox = (Textbox)nameBox.clone();
		newNameBox.setId(newNameBox.getId() + attributeCounter);
		newRow.appendChild(newNameBox);
		//new Type column
		Combobox typeBox = (Combobox)this.getFellow("attrTypes");
		Combobox newTypeBox = (Combobox)typeBox.clone();
		newTypeBox.setId(newTypeBox.getId() + attributeCounter);
		newRow.appendChild(newTypeBox);
		//new visibility cell
		Listbox visibilityBox = (Listbox)this.getFellow("attrVisibility");
		Listbox newVisibilityBox = (Listbox)visibilityBox.clone();
		newVisibilityBox.setId(newVisibilityBox.getId() + attributeCounter);
		newRow.appendChild(newVisibilityBox);
		//newVisibilityCell
		Textbox defaultBox = (Textbox)this.getFellow("attrDefault");
		Textbox newDefaultBox = (Textbox)defaultBox.clone();
		newDefaultBox.setId(newDefaultBox .getId() + attributeCounter);
		newRow.appendChild(newDefaultBox);
		
		//add everything to the end of the list
		rows.appendChild(newRow);
		attributeCounter++;
	}
	public void create(){
		logger.info("creating object");
		Textbox nameBox = (Textbox)this.getFellow("attrName0");
		logger.info("jee"+nameBox.getValue());
	}
	
	public void cancel(){
		logger.info("cancelling new Class creation");
		this.detach();
	}
}
